local lsp_jishi = fk.CreateSkill {
    name = "lsp_jishi",
}

Fk:loadTranslationTable {
    ["lsp_jishi"] = "姬蚀",
    [":lsp_jishi"] = "每轮限一次，一名角色的出牌阶段开始时，你可以令其从游戏外获得一张刺【杀】，此牌于此阶段内无次数限制且造成伤害后，受伤角色需依次弃置两张基本牌或一张非基本牌，否则其摸X张牌并翻面(X为其本回合受到的伤害总和)",

    ["#lsp_jishi-invoke"] = "姬蚀：是否对 %src 发动技能，令其获得一张刺【杀】？",

}

lsp_jishi:addEffect(fk.EventPhaseStart, {
    anim_type = "drawcard",
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(lsp_jishi.name) and target.phase == Player.Play and not target.dead and
            player:usedSkillTimes(lsp_jishi.name, Player.HistoryRound) == 0
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askToSkillInvoke(player, {
            skill_name = lsp_jishi.name,
            prompt = "#lsp_jishi-invoke:" .. player.id,
        })
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local card = room:printCard("stab__slash", math.random(1, 4), math.random(1, 13))
        room:moveCardTo(card, Card.PlayerHand, target, fk.ReasonJustMove, lsp_jishi.name, nil, true, player,
            "shuangjiang-phase")
    end,
})

lsp_jishi:addEffect("targetmod", {
    bypass_times = function(self, player, skill, scope, card, to)
        return player:hasSkill(lsp_jishi.name) and card and card:getMark("shuangjiang-phase") > 0
    end,
})

lsp_jishi:addEffect(fk.Damage, {
    anim_type = "control",
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
        return target == player and data.card and data.card:getMark("shuangjiang-phase") > 0 and
            not player.dead and not data.to.dead
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local skipOver = false
        if #data.to:getCardIds("h") > 0 and not data.to.dead then
            local card = room:askToDiscard(data.to, {
                min_num = 1,
                max_num = 1,
                include_equip = true,
                skill_name = lsp_jishi.name,
                cancelable = true,
                prompt = "姬蚀：请弃置一张非基本牌或一张基本牌，若弃置基本牌，则还需弃置一张基本牌"
            })
            if #card == 0 then skipOver = true end
            if #card > 0 and Fk:getCardById(card[1]).type == Card.TypeBasic then
                if #data.to:getCardIds("h") > 0 and not data.to.dead then
                    local ids = #table.filter(data.to:getCardIds("h"),
                        function(i) return Fk:getCardById(i).type == Card.TypeBasic end)
                    if ids == 0 then skipOver = true end
                    if ids > 0 then
                        local card2 = room:askToDiscard(data.to, {
                            min_num = 1,
                            max_num = 1,
                            include_equip = false,
                            skill_name = lsp_jishi.name,
                            cancelable = true,
                            pattern = ".|.|.|.|.|basic",
                            prompt = "姬蚀：再弃置一张基本牌",
                        })
                        if #card2 == 0 then skipOver = true end
                    else
                        skipOver = true
                    end
                end
            end
        else
            skipOver = true
        end
        if skipOver == true then
            local n = 0
            player.room.logic:getActualDamageEvents(1, function(e)
                if e.data.to == data.to then
                    n = n + e.data.damage
                end
                return false
            end)
            data.to:turnOver()
            data.to:drawCards(n, lsp_jishi.name)
        end
    end,
})
return lsp_jishi
